var WebSocket = require('rpc-websockets').Client
var ws = new WebSocket('ws://localhost:10020')

ws.on('open', function() {
  // call an RPC method with parameters
  console.info('aaaaaaaaaaaaaaaa connect success!')
  console.info('call C3_GetEccParams')
  ws.call('soa.callService',['C3_GetEccParams',{
            param_owner:'C3AGENT',
            param_code:'c3spa_version'
  }]).then(result =>{
    console.log(' call service result:',result)
  }).catch(err=>{
    console.log(' call service error',err)
  })

  console.info('call soa.callC3ImrCheck')
  ws.call('soa.callC3ImrCheck',['18959130026','WINDOWS']).then(result =>{
    console.log(' call service result:',result)
  }).catch(err=>{
    console.log(' call service error',err)
  })

  console.info('call soa.c3CheckServerTest')
  ws.call('soa.c3CheckServerTest',['192.168.0.17','80']).then(result =>{
    console.log(' call service result:',result)
  }).catch(err=>{
    console.log(' call service error',err)
  })
 /* 
  ws.call('aa.sum', [5, {a:'bbb'}]).then(function(result) {
    console.log('call sum the result:'+JSON.stringify(result))
  }).catch(err=>{
    console.log(' call service error',err)
  })
  ws.call('soa.callService', ['C3_GetEccParams','bbbbb']).then(
    (result) => {
    console.log('call sum the result:'+JSON.stringify(result))
  }).catch(err=>{
    console.log(' call service error',err)
  })
  */

  // send a notification to an RPC server
  ws.notify('openedNewsModule')

  // subscribe to receive an event
  ws.subscribe('feedUpdated')

  ws.on('feedUpdated', function() {
    updateLogic()
  })

  // unsubscribe from an event
  ws.unsubscribe('feedUpdated')

  // login your client to be able to use protected methods
  /*
  ws.login({'username': 'confi1', 'password':'foobar'}).then(function() {
    ws.call('account').then(function(result) {
      require('assert').equal(result, ['confi1', 'confi2'])
    })
  }).catch(function(error) {
    console.log('auth failed')
  })
  */

  // close a websocket connection
  //ws.close()
})